package com.sk.waste.app.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.sk.waste.app.R
import com.sk.waste.app.config.NetWorkConfig
import com.sk.waste.app.models.ImageModel

class SliderSpaceAdapter(val mContext: Context, val imageUrls: List<ImageModel>) : RecyclerView.Adapter<SliderSpaceAdapter.SliderSpaceViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SliderSpaceViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.adapter_slider, parent, false)
        return SliderSpaceViewHolder(view)
    }

    override fun onBindViewHolder(holder: SliderSpaceViewHolder, position: Int) {
        val item = imageUrls[position]
        Glide.with(mContext).load(NetWorkConfig.NET_URL_IMA_ROOT + item.img).transform(CenterCrop(), RoundedCorners(20))
            .placeholder(R.mipmap.img_banner_default_gray).error(R.mipmap.img_banner_default_gray).into(holder.imageView);
    }

    override fun getItemCount(): Int {
        return imageUrls.size
    }

    class SliderSpaceViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var imageView: ImageView = itemView.findViewById(R.id.vw_adapter_slider)
    }
}